package com.bhawana.examples;

import java.sql.* ;
class DbManager {
	

	private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
	private static final String DB_URL = "jdbc:mysql://localhost:3306/bhawana";
	private static final String DB_USER = "root";
	private static final String DB_PASSWORD = "root";
	
	static Connection conn=null;
	
	private static Connection getDBConnection() {
		 
		
 
		try {
 
			Class.forName(DB_DRIVER);
			System.out.println("drive success");
 
		} catch (ClassNotFoundException e) {
 
			System.out.println("driver failed : " + e);
 
		}
	      try {
			conn = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWORD);
			System.out.println("connection success");
		} catch (SQLException e) {
			System.out.println("COnnection failed : " + e);
			e.printStackTrace();
		}
		return conn;

	}
public boolean insert(String sql)   
	  {  
		Connection conn = null;
	  
		conn = getDBConnection();
	    try {
			Statement ps =conn.createStatement();
			 System.out.println("Inserting records into the table...");
			  ps.executeUpdate(sql);
			  System.out.println("insertion done");
			  return true;
	    } catch (SQLException e) {
			
			e.printStackTrace();
			return false;
		}
		
	  }
		
public boolean update(String sql)   
{  
	Connection conn = null;

	conn = getDBConnection();
  try {
		Statement ps =conn.createStatement();
		 System.out.println(" updating records into the table...");
		  ps.executeUpdate(sql);
		  System.out.println("updation done!!!");
		  return true;
  } catch (SQLException e) {
		
		e.printStackTrace();
		return false;
	}
	
} 

	
public boolean delete(String sql)   
{  
	Connection conn = null;

	conn = getDBConnection();
  try {
		Statement ps =conn.createStatement();
		 System.out.println(" deleting records into the table...");
		  ps.executeUpdate(sql);
		  System.out.println("deletion done!!!");
		  return true;
  } catch (SQLException e) {
		
		e.printStackTrace();
		return false;
	}
	
} 
}

	
			 